package com.tamecode.flowable.spring.test;

import org.flowable.engine.RepositoryService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 可以使用ClassPathXmlApplicationContext，也可以使用单元测试启动
 *
 * @Author: Liqc
 * @Date: 2021/11/4 16:48
 */
public class SpringFlowableStarter {

    public static void main(String[] args) {
        // 加载 Spring 配置，生成上下文
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                "SpringTransactionIntegrationTest-context.xml");

        // 2 种启动方式
        start1Way(applicationContext);
//        start2Way(applicationContext);
    }

    private static void start1Way(ClassPathXmlApplicationContext applicationContext) {
        RepositoryService repositoryService = (RepositoryService) applicationContext.getBean("repositoryService");
        String deploymentId = repositoryService
                .createDeployment()
                .addClasspathResource("holiday-request.bpmn20.xml")
                .deploy()
                .getId();
        System.out.println(deploymentId);
    }

    private static void start2Way(ApplicationContext applicationContext) {
        UserBean userBean = (UserBean) applicationContext.getBean("userBean");
        userBean.hello();
    }

}
